package cn.tedu.tmall.admin.mall.dao.repository.impl;

import cn.tedu.tmall.admin.mall.dao.repository.IMallCategoryCacheRepository;
import cn.tedu.tmall.common.pojo.po.MallCategoryCachePO;
import cn.tedu.tmall.common.pojo.vo.MallCategoryTreeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MallCategoryCacheRepository implements IMallCategoryCacheRepository {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void saveTreeCategory(List<MallCategoryTreeVO> mallCategoryTreeVOS) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("ALL",mallCategoryTreeVOS);
    }

    @Override
    public void saveCategoryByParentId(Long parentId, MallCategoryCachePO mallCategoryPO) {
        //key MALL_CATEGORY_BY_PARENT_ID_  value po
        //key 21 [太原] <--长治 [太原,长治]
        ListOperations listOperations = redisTemplate.opsForList();
        String key = "MALL_CATEGORY_BY_PARENT_ID_" + parentId;
        listOperations.rightPush(key,mallCategoryPO);
    }
}
